export function post(url,data) {
  return new Promise((resolve, reject) => {
    let xhr = new XMLHttpRequest();
    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xhr.onreadystatechange = function() {
      if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 304)) {
        resolve(xhr.responseText);
      }
    };
    xhr.onerror = function () {
      reject({
        errorType: 'onerror',
        xhr,
      });
    };
    let str = "jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMSJ9.NQWPTbY6vel6TuMyP2RMYZUBV9GJcMYTXLMWBQKM2io";
    for(let key in data){
      str = str + "&"+key+"="+data[key];
    }
    try {
      xhr.send(str);
    } catch (e) {
      reject({
        errorType: 'send_error',
        error: e,
      });
    }
  })
}
export function get(url,data) {
  return new Promise((resolve, reject) => {
    let xhr = new XMLHttpRequest();
    let str = "?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMSJ9.NQWPTbY6vel6TuMyP2RMYZUBV9GJcMYTXLMWBQKM2io";
    for(let key in data){
      str = str + "&"+key+"="+data[key];
    }
    xhr.open("GET", url+str, true);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xhr.onreadystatechange = function() {
      if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 304)) {
        resolve(xhr.responseText);
      }
    };
    xhr.onerror = function () {
      reject({
        errorType: 'onerror',
        xhr,
      });
    };
    try {
      xhr.send();
    } catch (e) {
      reject({
        errorType: 'send_error',
        error: e,
      });
    }
  })
}
